package cn.wolfcode.controller;

import cn.wolfcode.domain.Destination;
import cn.wolfcode.domain.Banner;
import cn.wolfcode.domain.Strategy;
import cn.wolfcode.domain.Travel;
import cn.wolfcode.query.BannerQuery;
import cn.wolfcode.service.IDestinationService;
import cn.wolfcode.service.IBannerService;
import cn.wolfcode.service.IStrategyService;
import cn.wolfcode.service.ITravelService;
import cn.wolfcode.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private IBannerService bannerService;
    @Autowired
    private IDestinationService destinationService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")BannerQuery qo){
        Page<Banner> page = bannerService.query(qo);
        model.addAttribute("page", page);
        return "/banner/list";
    }

    @RequestMapping("/listByAll")
    @ResponseBody
    public Object listByAll(){
        return destinationService.findAll();
    }



    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Banner banner){

        bannerService.saveOrUpdate(banner);
        return JsonResult.success();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){

        bannerService.delete(id);
        return JsonResult.success();
    }

    @RequestMapping("/getAllType")
    @ResponseBody
    public Object getAllType(){
        Map<String, Object> map = new HashMap<>();
        //查询攻略   查询游记
        List<Strategy> sts = strategyService.findAll();
        List<Travel> ts = travelService.findAll();

        map.put("sts",sts);
        map.put("ts",ts);

        return JsonResult.success();
    }


}
